package com.xju.subjectsystem.service.impl;

import com.xju.subjectsystem.mapper.ChapterMapper;
import com.xju.subjectsystem.pojo.Books;
import com.xju.subjectsystem.pojo.Chapter;
import com.xju.subjectsystem.pojo.Points;
import com.xju.subjectsystem.pojo.Section;
import com.xju.subjectsystem.service.ChapterService;
import org.springframework.data.relational.core.sql.In;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * -*- coding:utf-8 -*-
 *
 * @projectName: xju_-course_-kg_-master
 * @package: com.xju.subjectsystem.service.impl
 * @className: ChapterServiceImpl
 * @author: Eiard
 * @description: TODO : 
 * @date: 2024-12-17 22:37
 */
public class ChapterServiceImpl implements ChapterService {


    private final ChapterMapper chapterMapper;

    public ChapterServiceImpl(ChapterMapper chapterMapper) {
        this.chapterMapper = chapterMapper;
    }


    @Override
    public List<Chapter> selectByCsno(Integer csno) {
        return chapterMapper.selectByCsno(csno);
    }

    @Override
    public void getAllDirectory(Integer csno) {

    }

    @Override
    public Integer add(Chapter chapter) {
        chapterMapper.insert(chapter);

        // 返回主键
        return chapter.getChno();
    }

    @Override
    public List<Integer> batchAddChapters(List<Chapter> chapterList) {

        ArrayList<Integer> chnoList = new ArrayList<>();
        try {
            for (Chapter chapter : chapterList) {
                // 添加完成后的自增主键
                chnoList.add(this.add(chapter));
            }
        } catch (Exception e) {
            return null;
        }

        if (chnoList.size() == chapterList.size()) {
            return chnoList;
        }

        return null;
    }

    @Override
    public void addAllDirectory(List<Chapter> chapterList, List<Section> sectionList, List<Points> pointsList) {

    }
}
